package com.hqd.ch03.v16.utils;

import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

import java.util.ArrayList;
import java.util.List;

/**
 * 处理xml工具类
 */
public class DomUtils {
    public static List<Element> getChildElements(Element ele) {
        if (ele == null) {
            return null;
        }
        NodeList nl = ele.getChildNodes();
        List<Element> elements = new ArrayList<>();
        for (int i = 0; i < nl.getLength(); i++) {
            Node node = nl.item(i);
            if (node instanceof Element) {
                elements.add((Element) node);
            }
        }
        return elements;
    }
}
